// 鸡兔同笼的script.js代码
const totalNumInput = document.getElementById('totalNum');
const footNumInput = document.getElementById('footNum');
const calcBtn = document.getElementById('calcBtn');
const resultEle = document.getElementById('result');

calcBtn.addEventListener('click', () => {
    const total = parseInt(totalNumInput.value);
    const foot = parseInt(footNumInput.value);

    if (isNaN(total) || isNaN(foot) || total < 0 || foot < 0) {
        resultEle.textContent = '请输入非负有效数字';
        resultEle.style.color = 'orange';
        return;
    }

    const chicken = (4 * total - foot) / 2;
    const rabbit = total - chicken;

    if (chicken >= 0 && rabbit >= 0 && Number.isInteger(chicken) && Number.isInteger(rabbit)) {
        resultEle.textContent = `分别有鸡${chicken}只，有兔子${rabbit}只`;
        resultEle.style.color = 'blue';
    } else {
        resultEle.textContent = '无解';
        resultEle.style.color = 'red';
    }
});